Skip to content

[Repo Assist] test: add 25 unit tests for HtmlNode.ToString and HtmlDocument.ToString serialization#1769

Merged
dsyme merged 4 commits intomainfrom
repo-assist/test-htmlnode-tostring-2026-04-29-2b222bb36173d386
May 1, 2026
Merged

[Repo Assist] test: add 25 unit tests for HtmlNode.ToString and HtmlDocument.ToString serialization#1769
dsyme merged 4 commits intomainfrom
repo-assist/test-htmlnode-tostring-2026-04-29-2b222bb36173d386

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Summary

Adds 25 comprehensive unit tests for HtmlNode.ToString() and HtmlDocument.ToString() serialization in a new dedicated test file HtmlNodeSerialization.fs.

These tests provide regression coverage for the serialization behaviour (especially important alongside the perf changes in the companion PR for isVoidElement and newLine) and document the exact semantics of the serializer.

Tests Added

Leaf nodes (4 tests)

  • NewText → content string
  • Empty NewText → empty string
  • NewComment<!-- ... -->
  • NewCData<![CDATA[...]]>

Void elements (3 tests)

  • Individual void elements (area, br, img with attributes)
  • All 16 standard HTML void elements serialise as <name />

Non-void elements (4 tests)

  • Empty element → <div></div>
  • Text-only child → inline (no added whitespace)
  • Multiple text children → inline
  • Element children → indented at 2 spaces per level

Indentation and sibling behaviour (2 tests)

  • Nested elements get deeper indentation at each level
  • Text-only sibling elements serialise inline (no newline between them); element-children siblings each get their own line

Attributes (4 tests)

  • Single attribute
  • Multiple attributes in declared order
  • Attribute names lowercased via HtmlAttribute.New
  • Element names lowercased via NewElement

HtmlDocument.ToString() (5 tests)

  • No doctype → no <!DOCTYPE ...> prefix
  • With doctype → <!DOCTYPE html>\n prefix
  • Multiple root elements → all serialised
  • Empty root element list → empty string
  • Void element inside body → self-closing

Round-trip (1 test)

  • Manually constructed node serialises, parses back, and the structure is preserved

Test Status

Passed! - Failed: 0, Passed: 3005, Skipped: 0, Total: 3005 (net8.0, -p:NuGetAudit=false)

(2980 pre-existing + 25 new)

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@96b9d4c39aa22359c0b38265927eadb31dcf4e2a

…ng serialization

Covers:
- Leaf nodes: NewText, NewComment, NewCData
- Void elements: all 16 standard HTML void elements serialise as self-closing
- Non-void elements: empty, text-only (inline), element children (indented)
- Indentation: per-level 2-space indent; element vs. text-only sibling behaviour
- Attributes: single, multiple, name lower-casing
- HtmlDocument: with/without DOCTYPE, multiple root elements, empty element list
- Round-trip: manually-constructed node serialises then parses back correctly

25 tests pass (net8.0).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…3 to resolve GHSA-g94r-2vxg-569j

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 1, 2026

Commit pushed: 685f799

Generated by 🌈 Repo Assist, see workflow run. Learn more.

@dsyme dsyme marked this pull request as ready for review May 1, 2026 11:41
@dsyme dsyme merged commit a615f06 into main May 1, 2026
3 checks passed
@dsyme dsyme deleted the repo-assist/test-htmlnode-tostring-2026-04-29-2b222bb36173d386 branch May 1, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant